<?php

namespace App\Model\API;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class UserModel extends Model
{
    protected $table = 'api_user';
    protected $primaryKey = 'id';
    public $timestamps = true;
    const CREATED_AT = 'ctime';
    const UPDATED_AT = 'utime';
    protected $fillable = [
        'username','password','status','phone','email','ctime','utime','rand','token'
    ];
    protected $casts = [
        'ctime' => 'date:Y-m-d H:i:s',
        'utime' => 'date:Y-m-d H:i:s',
    ];


    /**
     * 插入一条数据
     */
    public static function insertOne($data)
    {
        return self::create($data);
    }
    /**
     * 查询一个字段
     */
    public static function selectOneField($where,$field)
    {
        return self::where($where)->value($field);
    }
    /**
     * 修改一条记录
     */
    public static function updateOne($where,$data)
    {
        return self::where($where)->update($data);
    }
    /**
     * 根据用户名查询该用户的数据
     */
    public static function selectUserByName($name)
    {
        return self::where('username',$name)->first();
    }
    /**
     * 更新用户token
     */
    public static function updateTokenById($id,$token)
    {
        return self::where('id',$id)->update(['token'=>$token]);
    }
}
